package com.antler.smt.portal.controller;

import com.antler.smt.portal.annotation.OperateCut;
import com.antler.smt.request.portal.GatherReq;
import com.antler.smt.request.portal.HiringReq;
import com.antler.smt.request.portal.PeopleReq;
import com.antler.smt.response.base.Result;
import com.antler.smt.service.portal.GatherService;
import com.antler.smt.service.portal.HiringService;
import com.antler.smt.service.portal.PeopleService;
import com.antler.smt.utils.LogUtil;
import com.antler.smt.validate.DataValidator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 工人、工程师 认证
 *
 * @author zhangyi
 * @date 2018/7/11 12:01
 */
@RestController
@Slf4j
@RequestMapping("/people")
@Api(description = "工人、共享工程师 操作")
public class PeopleController extends BaseController {
    @Resource
    private PeopleService peopleService;

    @Resource
    private HiringService hiringService;

    @Resource
    private GatherService gatherService;

    /**
     * 写入人员信息
     *
     * @param req 工人、工程师 实体
     * @return
     */
    @PostMapping("/entryInfo")
    @ApiOperation(value = "将工人、工程师的信息录入进去", httpMethod = "POST")
    @OperateCut(operationContent = "录入个人信息")
    public Result insertPeopleInfo(@RequestBody PeopleReq req) {

        DataValidator.isNull(req,"人员实体不能为空！");
        DataValidator.isBlank(req.getName(),"名字不能为空！");
        DataValidator.isBlank(String.valueOf(req.getProfessionalStatus()),"职业状态不能为空！");
        DataValidator.isBlank(String.valueOf(req.getAge()),"年龄不能为空！");
        DataValidator.isBlank(String.valueOf(req.getSex()),"性别不能为空！");
        DataValidator.isBlank(String.valueOf(req.getExpectedSalary()),"期望薪资不能为空！");
        DataValidator.isBlank(req.getCurrentResidence(),"现居地不能为空！");

        return peopleService.insertPeopleInfo(req, currentMember.getId());
    }


    /**
     * 写入收款信息
     *
     * @param gatherReq 工人、工程师 实体
     * @return
     */
    @PostMapping("/gather")
    @ApiOperation(value = "写入收款信息", httpMethod = "POST")
    @OperateCut(operationContent = "写入收款信息")
    public Result gather(@RequestBody GatherReq gatherReq) {

        return gatherService.insertGather(gatherReq);
    }

    /**
     * 修改工人、工程师的信息
     *
     * @param req
     * @return
     */
    @PostMapping("/updateInfo")
    @ApiOperation(value = "修改工人、工程的信息", httpMethod = "POST")
    @OperateCut(operationContent = "修改个人信息")
    public Result updatePeopleInfo(@RequestBody PeopleReq req) {
        DataValidator.isNull(req,"请求实体不能为空！");
        req.setMemberId(currentMember.getId());
        return peopleService.updatePeopleInfo(req);
    }

    /**
     * 查询当前的工人/工程师实体
     *
     * @return
     */
    @GetMapping("/selectPeopleInfo")
    @ApiOperation(value = "查询当前的工人/工程师实体简历信息", httpMethod = "GET")
    @OperateCut(operationContent = "查看当前的工人/工程师 履历信息")
    public Result selectPeopleInfo() {
        return peopleService.selectPeople(currentMember.getId());
    }


    /**
     * 共享工程师(招人)
     *
     * @return
     */
    @PostMapping("/setHiring")
    @OperateCut(operationContent = "共享工程师招人")
    @ApiOperation(value = "共享工程师(招人)", httpMethod = "POST")
    public Result hiring(@RequestBody HiringReq hiringReq) {
        return hiringService.insertHiring(hiringReq,currentMember.getId());
    }
    /**
     * 采购商，服务商首次发布需求需要完善信息(招人)
     *
     * @return
     */
    @GetMapping("/getHiring")
    @OperateCut(operationContent = "采购商，服务商首次发布需求需要完善信息(招人)")
    @ApiOperation(value = "采购商，服务商首次发布需求需要完善信息(招人)", httpMethod = "GET")
    public Result getHiring() {
        return hiringService.selectHiring(currentMember.getId());
    }
}
